<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>ordinal | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>ordinal</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>ordinal</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/customization/ordinal/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/07-customization/12-ordinal.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">// &#x4ECE; 2.12.0 &#x5F00;&#x59CB;
moment.updateLocale(&apos;en&apos;, {
    ordinal : Function
});
// &#x4ECE; 2.8.1 &#x81F3; 2.11.2
moment.locale(&apos;en&apos;, {
    ordinal : Function
});

// &#x5E9F;&#x5F03;&#x4E8E; 2.8.1
moment.lang(&apos;en&apos;, {
    ordinal : Function
});
</code></pre>

							</div>
<p><code>Locale#ordinal</code> &#x5E94;&#x662F;&#x4E00;&#x4E2A;&#x8FD4;&#x56DE;&#x7ED9;&#x5B9A;&#x6570;&#x5B57;&#x5E8F;&#x6570;&#x7684;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="language-javascript">moment.updateLocale(&apos;en&apos;, {
    ordinal : function (number, token) {
        var b = number % 10;
        var output = (~~ (number % 100 / 10) === 1) ? &apos;th&apos; :
            (b === 1) ? &apos;st&apos; :
            (b === 2) ? &apos;nd&apos; :
            (b === 3) ? &apos;rd&apos; : &apos;th&apos;;
        return number + output;
    }
});
</code></pre>
<p>&#x4ECE; <strong>2.0.0</strong> &#x5F00;&#x59CB;&#xFF0C;&#x5E8F;&#x6570;&#x51FD;&#x6570;&#x5E94;&#x540C;&#x65F6;&#x8FD4;&#x56DE;&#x6570;&#x5B57;&#x548C;&#x5E8F;&#x6570;&#x3002;&#x4EE5;&#x524D;&#x4EC5;&#x8FD4;&#x56DE;&#x5E8F;&#x6570;&#x3002;</p>
<p>&#x4ECE; <strong>2.1.0</strong> &#x5F00;&#x59CB;&#xFF0C;&#x6DFB;&#x52A0;&#x4E86;&#x4EE4;&#x724C;&#x53C2;&#x6570;&#x3002;&#x5B83;&#x662F;&#x8981;&#x6392;&#x5E8F;&#x7684;&#x4EE4;&#x724C;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;<code>M</code> &#x6216; <code>d</code>&#x3002;</p>
<p>&#x6709;&#x5173;&#x5E8F;&#x6570;&#x7684;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#xFF0C;&#x53C2;&#x9605; <a href="javascript:window.open('http://nodejs.cn/s/vqa83S');" target="_blank" rel="nofollow">Wikipedia</a>&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">// From 2.12.0 onward
moment.updateLocale(&apos;en&apos;, {
    ordinal : Function
});
// From 2.8.1 to 2.11.2
moment.locale(&apos;en&apos;, {
    ordinal : Function
});

// Deprecated in 2.8.1
moment.lang(&apos;en&apos;, {
    ordinal : Function
});
</code></pre>

							</div>
<p><code>Locale#ordinal</code> should be a function that returns the ordinal for a given number.</p>
<pre><code class="language-javascript">moment.updateLocale(&apos;en&apos;, {
    ordinal : function (number, token) {
        var b = number % 10;
        var output = (~~ (number % 100 / 10) === 1) ? &apos;th&apos; :
            (b === 1) ? &apos;st&apos; :
            (b === 2) ? &apos;nd&apos; :
            (b === 3) ? &apos;rd&apos; : &apos;th&apos;;
        return number + output;
    }
});
</code></pre>
<p>As of <strong>2.0.0</strong>, the ordinal function should return both the number and the ordinal. Previously, only the ordinal was returned.</p>
<p>As of <strong>2.1.0</strong>, the token parameter was added. It is a string of the token that is being ordinalized, for example: <code>M</code> or <code>d</code>.</p>
<p>For more information on ordinal numbers, see <a href="javascript:window.open('https://en.wikipedia.org/wiki/Ordinal_number_(linguistics)');" target="_blank" rel="nofollow">Wikipedia</a>.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>